<?php
namespace Store\Controller;
use Think\Controller;
class JoininController extends Controller
{
    public function  _initialize(){

        layout(false);

        $buzhou[] = 'tobe';
        $buzhou[] = 'tobe';
        $buzhou[] = 'tobe';
        $buzhou[] = 'tobe';
        switch(I('buzhou')){
            case 0 : $buzhou[0] = 'ongoing';break;
            case 1 : $buzhou[0] = 'passed';$buzhou[1] = 'ongoing';break;
            case 2 : $buzhou[0] = 'passed';$buzhou[1] = 'passed';$buzhou[2] = 'ongoing';break;
            case 3 : $buzhou[0] = 'passed';$buzhou[1] = 'passed';$buzhou[2] = 'passed';$buzhou[3] = 'ongoing';break;
        }

        $this->assign('buzhou',$buzhou);

    }

    //
    public function index(){
        $this->display();
    }

    //入住须知
    public function agreement()
    {
        $store_joinin = M('store_joinin');
        $re = $store_joinin->where(array('user_id'=>session('user_id')))->find();
        switch($re['joinin_state']){
            case 10 : $this->redirect('Joinin/audit',array('buzhou'=>3));break;
        }
        $re ? $this->redirect('Joinin/company',array('buzhou'=>1)):$this->display();
    }

    //公司信息认证
    public function company()
    {
        $store_joinin = M('store_joinin');
        $re = $store_joinin->where(array('user_id'=>session('user_id')))->find();

        //只有post时为添加，也有$re时为修改
        if(IS_POST)
        {
            $data                                   = I('post.');
            $data['company_address']                = getCityName(I('province_id'),I('city_id'),I('area_id'));
            $data['company_province_id']            = I('province_id');
            $data['company_city_id']                = I('city_id');
            $data['company_area_id']                = I('area_id');

            if($re){
                $store_joinin->where(array('user_id' => session('user_id')))->data($data)->save();
            }else{
                $data['user_id']                    = session('user_id');
                $data['user_name']                  = session('user_auth.user_name');
                $store_joinin->data($data)->add();
            }
            $this->redirect('Joinin/shop',array('buzhou'=>2));
        }

        $this->assign('company',$re);
        $this->assign('fanhui',I('fanhui'));
        $this->display();

    }

    //店铺信息认证
    public function shop()
    {
        if(IS_POST){
            $data   = I('post.');
            $data['joinin_state'] = 10;
            M('store_joinin')->where(array('user_id'=>session('user_id')))->data($data)->save();

            $this->redirect('Joinin/audit',array('buzhou'=>3));
        }
        $this->display();
    }

    //等待审核
    public function audit()
    {
        $this->display();
    }




}
